import React from 'react'

class CommentBox extends React.Component {
    constructor(props) {
        super(props)
        // this.state = {
        //     value: ''
        // }
        this.handleSubmit = this.handleSubmit.bind(this)
        // this.handleChange = this.handleChange.bind(this)

    }
    handleChange (event) {
        this.setState({
            value: event.target.value
        })
    }
    handleSubmit (event) {
        // alert(this.state.value)
        this.props.onAddComment(this.textInput.value)
        // alert(this.textInput.value)
        event.preventDefault()
    }


    render () {
        return (
            <form onSubmit={this.handleSubmit}>
                {/* <form > */}
                <div className="form-group">
                    <label>留言内容</label>
                    <input
                        type="text"
                        className="form-control"
                        placeholder="请输入内容"
                        ref={(textInput) => { this.textInput = textInput }}
                    // onChange={(event) => this.handleChange(event)}
                    // onChange={this.handleChange}
                    // value={this.state.value}
                    />
                </div>

                <button type="submit" className="btn btn-primary">留言</button>
        <p>已有{this.props.commentsLength}条评论</p>


            </form>

        )
    }
}

export default CommentBox